<title>数据字典列表</title>
<!-- /section:settings.box -->
<div class="row list_dict_child">
	<div class="col-xs-12">
		<div class="row">
			<div class="col-xs-12">
				<div>
					<table class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>ID</th>
								<th>排序</th>
								<th>字典名称</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody class="data" style="display: table-row-group;">
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="pull-left">
			<button type="button" class="btn btn-info add" data-identity="add"
				title="添加">
				<i class="ace-icon glyphicon glyphicon-plus"></i>添加
			</button>
		</div>
		<!--分页-->
		<nav class="pull-right">
			<ul class="pagination">
				<li><a class="first" href="javascript:void(1);"
					aria-label="Previous"> 首页</a></li>
				<li><a class="prev" href="javascript:void(1);"><i
						class="ace-icon fa fa-angle-double-left"></i>上一页</a></li>
				<li><a class="next" href="javascript:void(1);">下一页<i
						class="ace-icon fa fa-angle-double-right"></i></a></li>
				<li><a class="last" href="javascript:void(1);" aria-label="Next">尾页</a>
				</li>
				<li><a class="go_page" href="javascript:void(1);">跳转到</a></li>
				<li><input type="text" style="width: 30px" class="go_num" value="1"></li>
				<li>页</li>
			</ul>
		</nav>
		<!-- TemplteHidden -->
		<table class="list-tpl hidden">
			<tr>
				<td>id</td>
				<td>ordernum</td>
				<td>name</td>
				<td>
					<button type="button" class="btn btn-mini btn-info up" title="上移">上移</button>
					<button type="button" class="btn btn-mini btn-info down" title="下移">下移</button>
					<button type="button" class="btn btn-mini btn-info edit" title="编辑">
						<i class="ace-icon glyphicon glyphicon-edit"></i>
					</button>
					<button type="button" class="btn btn-mini btn-danger delete"
						title="删除">
						<i class="ace-icon glyphicon glyphicon-remove"></i>
					</button>
				</td>
			</tr>
		</table>
		<!-- TemplteHidden -->
		<!-- PAGE CONTENT ENDS -->
		<script type="text/javascript">
		var scripts = [null,null];
		$('.page-content-area').ace_ajax('loadScripts', scripts, function() {		
			var $scope=$('.list_dict_child');	
			function pageInit(page){
			    $('.data',$scope).empty();
			    $.getJSON(page.url,
					{
						page:page.pi
					},					
					function(ret)
					{
						if(ret.status>0)
						{
							var $data=$('.data',$scope);
							$data.hide();
							$data.empty();
							var data=ret.data;
							pageObj.set_page_count_without_action(ret.page_count);//meta['page_count']
							for(var i in data)
							{
								var v=data[i];
								var id=v['id'];
								var $item=$('.list-tpl tr',$scope).clone();
								$('td:eq(0)',$item).attr('data-identity','id-'+id).text(id);
								$('td:eq(1)',$item).attr('data-identity','ordernum_label-'+id).text(v['sys_order_num']);
								$('td:eq(2)',$item).attr('data-identity','id-'+id).text(v['sys_value']);
								if(i>0){
									$('td:eq(3) .up',$item).attr('data-identity','up-'+id);
								}else
								{
								    $('td:eq(3) .up',$item).remove();;
								}
								if(i<data.length-1){
									$('td:eq(3) .down',$item).attr('data-identity','down-'+id);
								}else
								{
								    $('td:eq(3) .down',$item).remove()
								}
								$('td:eq(3) .edit',$item).attr('data-identity','edit-'+id);
								$('td:eq(3) .delete',$item).attr('data-identity','delete-'+id);						
								$data.append($item);
							}
							$data.show();
						}
						else {
							pageObj.set_page_count_without_action(1)
							//message_box.show(ret.data,'error');
						}
					});
			}	
			pageObj=new pagination({
				'url':'/sys/ajax_dict_list?dt_pk=<?=$dt_pk?>',
				'page_count':9,
				'show_callback':function(page)
				{
				    pageInit(page);
				}
			});
			$('.first',$scope).click(function(){
				pageObj.first_page();
				$('.go_num',$scope).val('1');
			});
			$('.prev',$scope).click(function(){
				pageObj.prev_page();
				$('.go_num',$scope).val(pageObj.get_page_index());
			});
			$('.next',$scope).click(function(){
				pageObj.next_page();
				$('.go_num',$scope).val(pageObj.get_page_index());
			});
			$('.last',$scope).click(function(){
				pageObj.last_page();
				$('.go_num',$scope).val(pageObj.get_page_index());
			});
			//跳转输入框
			$('.go_num',$scope).change(function(){
				var num=$(this).val();
				if(num>pageObj.get_page_count()){
					$(this).val(pageObj.get_page_count());
				}else if(num<1){
					$(this).val(1);
				}
			})
			//跳转至指定页面
			$('.go_page',$scope).click(function()
			{
				var num=$('.go_num',$scope).val();
				pageObj.go_page(num);
				$('.go_num',$scope).val(pageObj.get_page_index());
			});
			$scope.delegate('[data-identity="add"]','click',function(){
				var	url='/sys/dict_editor?dt_pk=<?=$dt_pk?>&dialog=1';
				gDialog.fCreate({title:'增加',url:url,width:600}).show();
			}).delegate('[data-identity^="edit-"]','click',function(){
				var id=$(this).attr('data-identity').split('-')[1];
				var	url='/sys/dict_editor?dt_pk=<?=$dt_pk?>&did='+id;
				gDialog.fCreate({title:'编辑',url:url,width:600}).show();
			}).delegate('[data-identity^="delete-"]','click',function(){				
				var id=$(this).attr('data-identity').split('-')[1];
				var	url='/sys/ajax_dict_delete';
				gDialog.fConfirm('删除数据字典','你确定执行这个操作么？',function(ret){
					if(ret){
						$.post(url,{id:id},function(ret){
							if(ret.status>0) {
								message_box.show('删除成功','success');
								pageObj.cur_page();
							} else {
								message_box.show(ret.data,'error');
							}
						},'json');
					}
				});
			}).delegate('[data-identity^="up-"]','click',function(){				
				var id=$(this).attr('data-identity').split('-')[1];
				var	url='/sys/ajax_dict_up';				
						$.post(url,{id:id},function(ret){
							if(ret.status==200) {
								message_box.show('移动成功','success');
								pageObj.cur_page();
							} else {
								message_box.show(ret.data,'error');
							}
						},'json');
				
			}).delegate('[data-identity^="down-"]','click',function(){				
				var id=$(this).attr('data-identity').split('-')[1];
				var	url='/sys/ajax_dict_down';				
				$.post(url,{id:id},function(ret){
						if(ret.status==200) {
								message_box.show('移动成功','success');
								pageObj.cur_page();
							} else {
								message_box.show(ret.data,'error');
							}
				},'json');					
			});		
		})
		
		</script>
	</div>
	<!-- /.col -->
</div>
